<?php

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 * Description of login
 *
 * @author james
 */
class SystemLogin extends CI_Model{
    // Metodos
    private $email, $senha;
    private $key;

    private $error;

    function __construct() {
        parent::__construct();
    }


    function setEmail($email){
        $this->email = $email;
        return $email;
    }

    function setSenha($senha){
        $this->senha = $senha;
        return $senha;
    }

    function logar($email = FALSE, $senha = FALSE){

        //
        $this->email = ($email != FALSE) ? $email : $this->input->post('email');
        $this->senha = ($senha != FALSE) ? $senha : $this->input->post('password');

        if($this->verificaEmail($this->email)){

            $this->load->library('form_validation');
            $this->form_validation->set_rules('email', 'Email', 'trim|required|valid_email|xss_clean');
            $this->form_validation->set_rules('password', 'Password', 'trim|required|md5');

            return $this->form_validation->run().'<--';

            //$query = $this->db->get();


        }else{
           return FALSE;
        }




    }

    function verificaEmail($email = FALSE){
        //
        $this->email = ($email != FALSE) ? $email : $this->email;

        $this->db->select('usuario_email');
        $qr = $this->db->get_where('usuario', array('usuario_email' => $this->email));

        $count = $this->db->count_all_results();

        if($count == 0){
            // MENSAGEM DE ERROR
            $this->error = "";
            return FALSE;
        }else{
            return TRUE;
        }

    }

    function setCookie(){

    }

    function setSession(){

    }




}